package javase2.day02.card;


/** �˿��� Card extends Object Card�Ƕ����һ�� ɶ���Ƕ��� */
public class Card {
  /** ��ɫ */
  private int suit;//ʵ���, ÿ���˿���ʵ�����Լ��Ļ�ɫ
  /** ���� 0���3, 1���4, 2���5 */
  private int rank;//ʵ���, ÿ���˿���ʵ�����Լ��ĵ���
  
  public final static int CLUB = 0; //÷��
  public static final int DIAMOND = 1; //����(��ʯ)
  public static final int HEART = 2; //����(����)
  public static final int SPADE = 3; //����(����)
  public static final int JOKER = 4; //��

  public final static int THREE = 0;
  public final static int FOUR = 1;
  public final static int FIVE = 2;
  public final static int SIX = 3;
  public final static int SEVEN = 4;
  public final static int EIGHT = 5;
  public final static int NINE = 6;
  public final static int TEN = 7;
  public final static int JACK = 8;//J
  public final static int QUEEN = 9;//Q
  public final static int KING = 10;//K
  public final static int ACE = 11;//A
  public final static int DEUCE = 12; //2
  public final static int BLACK = 13; //С��
  public final static int COLOR = 14;//����

  
  public Card() {
  }
  
  public Card(int suit, int rank){
    setRank(rank);
    setSuit(suit);
  }
  
  public int getRank() {
    return rank;
  }
  /** ���µ��� */
  public void setRank(int rank) {
    if(rank<THREE || rank>COLOR){
      throw new RuntimeException("����!");
    }
    this.rank = rank;
  }
  public int getSuit() {
    return suit;
  }
  public void setSuit(int suit) {
    if(suit<CLUB  || suit>JOKER){
      throw new RuntimeException("����!");
    }
    this.suit = suit;
  }
  private final static String[] SUIT_NAMES ={"梅花","方块","黑桃","草花",""};
  private final static String[] RANK_NAMES ={"3","4","5","6","7","8","9",
      "10","J","Q","K","A","2","小王","大王"};

  public String toString() {
    //rank suit
     return SUIT_NAMES[suit] + RANK_NAMES[rank];
  }
  public int hashCode() {
    return suit * 10000 + rank;
  }
  public boolean equals(Object obj) {
    if(obj==null)
      return false;
    if(this==obj)
      return true;
    if(obj instanceof Card){
      Card other = (Card)obj;
      return this.suit == other.suit && 
             this.rank == other.rank ;
    }
    return false;
  }
  
}








